package com.example.todolist.configuration;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


/**
 * @author :xiaosheng
 * @description :
 * @create :2022-01-08 12:37:00
 */
@Data
@Configuration
@EnableSwagger2
//http://localhost:6070/api/swagger-ui/
public class SwaggerConfig {
    /**
     * 是否开启swagger，生产环境一般关闭，所以这里定义一个变量
     */
    private final Boolean enable = true;

    /**
     * 项目应用名
     */
    private final String applicationName = "协助小程序系统" ;

    /**
     * 项目版本信息
     */
    private final String applicationVersion = "1.0";

    /**
     * 项目描述信息
     */
    private final String applicationDescription = "毕设项目";



    @Bean
    public Docket docket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .pathMapping("/")

        // 定义是否开启swagger，false为关闭，可以通过变量控制，线上关闭
                .enable(enable)

        //配置api文档元信息
                .apiInfo(apiInfo())

        // 选择哪些接口作为swagger的doc发布
                .select()

        //apis() 控制哪些接口暴露给swagger，
        // RequestHandlerSelectors.any() 所有都暴露
        // RequestHandlerSelectors.basePackage("net.xdclass.*")  指定包位置
        // withMethodAnnotation(ApiOperation.class)标记有这个注解 ApiOperation
                .apis(RequestHandlerSelectors.any())

                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title(applicationName)
                .description(applicationDescription)
                .contact(new Contact("蔡秋秋","http://www.baidu.com", "18666666666@163.com"))
                .version(applicationVersion)
                .build();
    }

}
